package itdep.common.domain.hibernate;

import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;

/**
 * @author $Author: ikhalopik $
 * @version $Revision: 4 $   $Date: 2010-06-10 13:13:16 +0000 (Thu, 10 Jun 2010) $
 */
public class OpenSessionInViewFilterEx extends OpenSessionInViewFilter {

	@Override
	protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
		Session session = SessionFactoryUtils.getSession(sessionFactory, true);
		session.setFlushMode(FlushMode.COMMIT);
		return session;
	}

	@Override
	protected void closeSession(final Session session, final SessionFactory sessionFactory) {
		session.flush();
		super.closeSession(session, sessionFactory);
	}
}
